/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */
define(['adminapp','moment','bootstrap-daterangepicker','jquery-easy-pie-chart','jquery.sparkline'],function ($app) {
    $app.navactive('dashboard');
    require(['custom/index','jquery-flot','jquery-flot-resize','jquery-flot-pie'], function(){
        Index.init();
        Index.initCharts(); // init index page's custom scripts
        Index.initChat();
        Index.initMiniCharts();
        Index.initDashboardDaterange();


        var data = [];
        var totalPoints = 250;

        // random data generator for plot charts

        function getRandomData() {
            if (data.length > 0) data = data.slice(1);
            // do a random walk
            while (data.length < totalPoints) {
                var prev = data.length > 0 ? data[data.length - 1] : 50;
                var y = prev + Math.random() * 10 - 5;
                if (y < 0) y = 0;
                if (y > 100) y = 100;
                data.push(y);
            }
            // zip the generated y values with the x values
            var res = [];
            for (var i = 0; i < data.length; ++i) res.push([i, data[i]])
            return res;
        }
        //server load
        var options = {
            series: {
                shadowSize: 1
            },
            lines: {
                show: true,
                lineWidth: 0.5,
                fill: true,
                fillColor: {
                    colors: [{
                                 opacity: 0.1
                             }, {
                                 opacity: 1
                             }
                    ]
                }
            },
            yaxis: {
                min: 0,
                max: 100,
                tickColor: "#eee",
                tickFormatter: function (v) {
                    return v + "位";
                }
            },
            xaxis: {
                show: false
            },
            colors: ["#6ef146"],
            grid: {
                tickColor: "#eee",
                borderWidth: 0
            }
        };

        var updateInterval = 30;
        var plot = $.plot($("#chart_4"), [getRandomData()], options);

        function update() {
            plot.setData([getRandomData()]);
            plot.draw();
            setTimeout(update, updateInterval);
        }
        update();

    });
    return {};
});